<?php
/**
 * Created by JetBrains PhpStorm.
 * User: miaodb
 * Date: 11-10-27
 * Time: 下午4:35
 * To change this template use File | Settings | File Templates.
 */
 
class CLI_Updaterate extends CLI
{


    /**
     * 脚本主方法
     *
     * @return void
     */
    public function main()
    {
        $select = DB::select()->from('order_rates')->where('order_id', '=', 0);
        $iterator = new Db_Iterator($select, 'default', 10);
        $i = 0;
        while ($iterator->valid())
        {
            // 遍历数据
			foreach ($iterator->current() as $order_rate)
            {
                    $seller_nick = DB::select('members.nickname')
                            ->from('members')
                            ->join('shops')
                            ->on('members.member_id','=','shops.member_id')
                            ->where('shops.shop_id','=',$order_rate['shop_id'])
                            ->fetch_one();

                    if ($order_rate['buyer_flag']) {
                        //买家评价

                        $data = array(
                            'trade_id'=>0,
                            'order_id'=>0,
                            'role'=>0,
                            'nick'=>$order_rate['nickname'],
                            'result'=>$order_rate['buyer_comment_score'],
                            'rated_nick'=>$seller_nick,
                            'item_id'=>$order_rate['goods_id'],
                            'item_title'=>$order_rate['goods_title'],
                            'item_price'=>$order_rate['price'],
                            'prop_str'=>$order_rate['prop_str'],
                            'content'=>$order_rate['buyer_comment'],
                            'created'=>$order_rate['buyer_comment_time'],
                            'is_anonymity'=>$order_rate['is_anonymity'],
                            'deleted'=>$order_rate['buyer_deleted'],

                        );
                        DB::insert('tc_rate', array_keys($data))->values(array_values($data))->execute();

                    }

                    if ($order_rate['seller_flag']) {
                        //商家评价
                        $data = array(
                            'trade_id'=>0,
                            'order_id'=>0,
                            'role'=>1,
                            'nick'=>$seller_nick,
                            'result'=>$order_rate['seller_comment_score'],
                            'rated_nick'=>$order_rate['nickname'],
                            'item_id'=>$order_rate['goods_id'],
                            'item_title'=>$order_rate['goods_title'],
                            'item_price'=>$order_rate['price'],
                            'prop_str'=>$order_rate['prop_str'],
                            'content'=>$order_rate['seller_comment'],
                            'created'=>$order_rate['seller_comment_time'],
                            'is_anonymity'=>$order_rate['is_anonymity'],
                            'deleted'=>$order_rate['seller_deleted'],

                        );
                        DB::insert('tc_rate', array_keys($data))->values(array_values($data))->execute();
                    }


            }
            echo '>';
                $iterator->next();
        }
        die;

        }

    }